package com.example.demodb.controller;

import com.example.demodb.entity.RecoveryKnowledge;
import com.example.demodb.entity.TodoItem;
import com.example.demodb.service.RecoveryKnowledgeService;
import com.example.demodb.service.TodoItemService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RecoveryKnowledgeController {
    @Resource
    private RecoveryKnowledgeService recoveryKnowledgeService;
    @GetMapping("/RecoveryKnowledgeController/findAll")
    @CrossOrigin
    public List<RecoveryKnowledge> findAll(){
        return recoveryKnowledgeService.findAll();
    }

    @GetMapping("/RecoveryKnowledgeController/deleteById/{id}")
    @CrossOrigin
    public void delete(@PathVariable Long id){
        recoveryKnowledgeService.delete(id);
    }

    //借口原名为RecoveryKnowledgeController/saveUser, 将检查用户是否存在,新增用户的功能放到一起
    //如果这里不分开写的话,也合理,因为check的返回值就可以定义成int了,这样子就不会出现空对象前端无法识别的问题
    @PostMapping("/RecoveryKnowledgeController/add") //RO表示该接口 会返回一个对象
    @CrossOrigin
    public RecoveryKnowledge add(@RequestBody RecoveryKnowledge recoveryKnowledge){
        return recoveryKnowledgeService.add(recoveryKnowledge);//返回为空的话,就说明为0
    }

    @GetMapping("/RecoveryKnowledgeController/findAllByCategory/{category}") //RO表示该接口 会返回一个对象
    @CrossOrigin
    public List<RecoveryKnowledge> findAllByCategory(@PathVariable Integer category){
        return recoveryKnowledgeService.findAllByCategory(category);//返回为空的话,就说明为0
    }

    @PostMapping("/RecoveryKnowledgeController/update") //RO表示该接口 会返回一个对象
    @CrossOrigin
    public void update(@RequestBody RecoveryKnowledge recoveryKnowledge){
        recoveryKnowledgeService.update(recoveryKnowledge);//返回为空的话,就说明为0
    }
}
